home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Graphics Samples / Caps Attached To a Curve ƒ / caps attached to a curve.c next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  4.5 KB  |  162 lines  |  [TEXT/KAHL]

  1. /*
  2.     caps attached to a curve.c 
  3.     
  4.     This file contains the calls to create a "thick" curve and attach a cap to each end of the
  5.     curve. 
  6.         
  7.     NOTES: 
  8.     • This file requires the following files to run correctly:
  9.         "graphics shell.c", "ColorLibrary.c", "GraphicsDebugLibrary.c",
  10.         "ShapeLibrary.c", "TransformLibrary.c".
  11.         
  12.     • This file prints the "best" in landscape mode.
  13.  
  14.  
  15.     Change History:
  16.  
  17.        4/96    bob        Updated #includes to support changed GX Library names.
  18.                     Updated the note regarding the files needed to run, and copyright date.
  19.  
  20.     ©1992 - 1996 Apple Computer, Inc. 
  21.     All rights reserved. 
  22. */
  23.  
  24.  
  25. #include <events.h>
  26. #include <windows.h>
  27.  
  28. #include <GXErrors.h>
  29. #include "GraphicsLibraries.h"
  30. #include <GXEnvironment.h>
  31. #include "graphics shell.h"
  32.  
  33. //
  34. //  Set up the title and size of the window 
  35. //
  36. Str255         gWindowTitle = "\p Caps Attached To a Curve";
  37. Rect         gWindowQDRect  = {50, 20, 275, 350};
  38.  
  39. //
  40. //    gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  41. //    in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  42. //    With  gGraphicsHeapSize set to 10k, I had 3 free blocks left in the graphics gxHeap. Sounds good to me.
  43. //
  44. long        gGraphicsHeapSize = 10;
  45.  
  46. gxShape     gShape;
  47. short        gClickNumber;
  48.  
  49.  
  50.  
  51. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  52.  
  53. void DoInitialization(gWindow)
  54. WindowPtr gWindow;
  55. {
  56.     gxCurve         curveGeometry = {ff(25), ff(125), ff(100), 0, ff(225), ff(125)};    
  57.     gxShape         arrowHead, arrowTail;
  58.     long            arrowHeadPolygonGeometry[] = {    4, // Number of points,
  59.                                                        -ff(2)-fixed1/2, 0,
  60.                                                         0, fixed1, 
  61.                                                          fixed1 + fixed1/2, 0, 
  62.                                                        0, -fixed1};
  63.                                                
  64.     long             arrowTailPolygonGeometry[] = {    5, // Number of points,
  65.                                                      -fixed1, 0, 
  66.                                                       0, fixed1, 
  67.                                                       ff(2), fixed1, 
  68.                                                       ff(2), -fixed1, 
  69.                                                       0, -fixed1};
  70.      gxCapRecord     theCapRecord;
  71.  
  72.      InitCommonColors();
  73.  
  74.     gShape = GXNewCurve (&curveGeometry);
  75.     
  76.     //
  77.     //    Create the cap shapes
  78.     //
  79.     arrowHead = NewPolygon((gxPolygon *) &arrowHeadPolygonGeometry);
  80.     arrowTail = NewPolygon((gxPolygon *) &arrowTailPolygonGeometry);
  81.  
  82.     //
  83.     //    We needed to reverse the direction of the contour to prevent a hole from being drawn
  84.     //    were the arrowHead or arrowTail capped the curve. This was an issue because the 
  85.     //    shape fill of the curve is openFrame and the arrowHead and arrowTail are evenOdd. 
  86.     //
  87.     GXReverseShape(arrowHead, 1);
  88.     GXReverseShape(arrowTail, 1);
  89.  
  90.     //
  91.     //    Add the appropriate shape for start cap and end cap
  92.     //
  93.     theCapRecord.startCap = arrowHead;
  94.     theCapRecord.endCap = arrowTail;
  95.     theCapRecord.attributes = gxNoAttributes;
  96.  
  97.     //
  98.     //    Add the cap record to our "gShape"
  99.     //
  100.     GXSetShapeCap(gShape, &theCapRecord);
  101.     
  102.     //
  103.     //    We do no need the cap shapes because they have been copied into the cap record which is
  104.     //    now part of the style used by "gShape".
  105.     //
  106.     GXDisposeShape(arrowHead);
  107.     GXDisposeShape(arrowTail);
  108.     
  109.     GXSetShapePen(gShape, ff(15));
  110.     SetShapeCommonColor(gShape, red);
  111.     GXMoveShape (gShape, ff(35), 0);
  112.     
  113.     gClickNumber = 1;
  114. }
  115.  
  116. /*------ DoClick ---------------------------------------------------------------------------------------*/
  117.  
  118. void DoClick( orgMouseLoc, theWindow )
  119. gxPoint        orgMouseLoc;
  120. WindowPtr     theWindow;
  121. {
  122. }
  123.  
  124.  
  125.  
  126.  
  127. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  128.  
  129. void DoDraw(gWindow)
  130. WindowPtr gWindow;
  131. {
  132.     GXDrawShape (gShape);
  133. }
  134.  
  135.  
  136. /*------ DoDispose -------------------------------------------------------------------------------------*/
  137.  
  138. void DoDispose(gWindow)
  139. WindowPtr gWindow;
  140. {
  141.     /**  
  142.         You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  143.         form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  144.         call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  145.         SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  146.         can turn notices on in this file by setting gDebugging = TRUE (above).
  147.     **/
  148.     GXDisposeShape(gShape);  
  149.      GXDisposeShape(gWindowBoundsShape);  
  150.        DisposeCommonColors();
  151.        DisposeWindow(gWindow);
  152. }
  153.     
  154.  
  155.  
  156. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  157.  
  158. void DoIdle(gWindow)
  159. WindowPtr gWindow;
  160. {
  161. }
  162.